﻿using Autofac;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;

namespace SH.Common
{
    public class AppService
    {
        private static IHttpContextAccessor _httpContextAccessor;
        public static void Configure(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
        /// <summary>
        /// autofac容器
        /// </summary>
        public static ILifetimeScope AutofacContainer { get; set; }
        public static HttpContext HttpContext
        {
            get => _httpContextAccessor.HttpContext;
            set => _httpContextAccessor.HttpContext = value;
        }

        public static IServiceCollection Services { get; set; }

        public static IConfiguration Configuration { get; set; }

        //
        //public static HttpContext CurrentHttpContext
        //{
        //    get
        //    {
        //        var factory = Services.BuildServiceProvider().GetService(typeof(IHttpContextAccessor));
        //        HttpContext context = ((IHttpContextAccessor)factory).HttpContext;
        //        return context;
        //    }
        //}

    }
}
